import Router from 'next/router'
import { Toast } from 'antd-mobile';

// 路由开始切换时触发
Router.events.on('routeChangeStart', (url) => {
  console.log('routeChangeStart = ', url)
  Toast.loading('加载中...', 100, () => {
    Toast.info('网络可能有问题哦');
  });
})

// 完成路由切换时触发
Router.events.on('routeChangeComplete', (url) => {
  console.log('routeChangeComplete = ', url)
  Toast.hide()
})

// 路由切换报错时触发
Router.events.on('routeChangeError', (err, url) => {
  console.log('routeChangeError = ', err, url)
  Toast.hide()
})

// 浏览器 history 模式开始切换时触发
Router.events.on('beforeHistoryChange', (url) => {
  console.log('beforeHistoryChange = ', url)
})

// 开始切换 hash 值但是没有切换页面路由时触发
Router.events.on('hashChangeStart', (url) => {
  console.log('hashChangeStart = ', url)
})

// 完成切换 hash 值但是没有切换页面路由时触发
Router.events.on('hashChangeComplete', (url) => {
  console.log('hashChangeComplete = ', url)
})